package com.lion.tag.grid;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import com.lion.tag.LionBaseTag;
import com.lion.tag.util.AppendUtil;

public class DataGridItem extends LionBaseTag {
	private static final long serialVersionUID = 7374448965098543842L;
	private String field;// 列对应数据参数
	private String width;// 列宽
	private String halign;// 列头对齐方式(center|left|right)
	private String align;// 列内容对齐方式(center|left|right)
	private String formatter;// 格式化函数
	private String sortable;// 允许排序（true|false）

	@Override
	public int doStartTag() throws JspException {
		StringBuilder sb = new StringBuilder(200);
		sb.append("<th ");
		int hasData = 0;
		hasData = AppendUtil.appendOptionData(sb, hasData, "field", field, true);
		hasData = AppendUtil.appendOptionData(sb, hasData, "width", width,false);
		hasData = AppendUtil.appendOptionData(sb, hasData, "halign", halign,true);
		hasData = AppendUtil.appendOptionData(sb, hasData, "align", align, true);
		hasData = AppendUtil.appendOptionData(sb, hasData, "formatter",formatter, true);
		hasData = AppendUtil.appendOptionData(sb, hasData, "sortable",sortable, true);
		if(hasData==1){
			sb.append("\">");
		}else{
			sb.append(">");
		}
		return EVAL_BODY_INCLUDE;
	}

	@Override
	/**  
	 *  doEndTag：当JSP容器遇到自定义标签的结束标志，就会调用doEndTag()方法。doEndTag()方法也返回一个整数值，用来决定程序后续流程。  
	 *  A.Tag.SKIP_PAGE：表示立刻停止执行网页，网页上未处理的静态内容和JSP程序均被忽略任何已有的输出内容立刻返回到客户的浏览器上。  
	 *  B.Tag.EVAL_PAGE：表示按照正常的流程继续执行JSP网页  
	 */
	public int doEndTag() throws JspException {
		try {
			pageContext.getOut().write("</th>");
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

	/**
	 * @return the field
	 */
	public String getField() {
		return field;
	}

	/**
	 * @param field
	 *            the field to set
	 */
	public void setField(String field) {
		this.field = field;
	}

	/**
	 * @return the width
	 */
	public String getWidth() {
		return width;
	}

	/**
	 * @param width
	 *            the width to set
	 */
	public void setWidth(String width) {
		this.width = width;
	}

	/**
	 * @return the halign
	 */
	public String getHalign() {
		return halign;
	}

	/**
	 * @param halign
	 *            the halign to set
	 */
	public void setHalign(String halign) {
		this.halign = halign;
	}

	/**
	 * @return the align
	 */
	public String getAlign() {
		return align;
	}

	/**
	 * @param align
	 *            the align to set
	 */
	public void setAlign(String align) {
		this.align = align;
	}

	/**
	 * @return the formatter
	 */
	public String getFormatter() {
		return formatter;
	}

	/**
	 * @param formatter
	 *            the formatter to set
	 */
	public void setFormatter(String formatter) {
		this.formatter = formatter;
	}

	/**
	 * @return the sortable
	 */
	public String getSortable() {
		return sortable;
	}

	/**
	 * @param sortable
	 *            the sortable to set
	 */
	public void setSortable(String sortable) {
		this.sortable = sortable;
	}

}
